package com.example.administrator.readbook.utils;

import android.os.Environment;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * Created by Administrator on 2018/10/31.
 */

public class CacheFileUtils {

    public static void saveChapterFile(String chapterTitle, String chapterStr) {
        String filePath = Environment.getDownloadCacheDirectory().getAbsolutePath() + File.separator + chapterTitle + ".txt";
        try {
            File file = new File(filePath);
            if (!file.exists()) {
                File dir = new File(file.getParent());
                dir.mkdir();
                file.createNewFile();
            }
            FileOutputStream outputStream = new FileOutputStream(file);
            outputStream.write(chapterStr.getBytes());
            outputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
